package org.springblade.oa.wrappper;

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.oa.entity.Bxfymx;
import org.springblade.oa.service.IBxfymxService;
import org.springblade.oa.service.IExpenseAccountService;
import org.springblade.oa.vo.BxfymxVO;
import org.springblade.system.feign.IDictClient;

/**
 * @author LK
 * @version 1.0.0
 * @Title: BxfymxWrapper.java
 * @Description: TODO    返回视图层所需要报销费用明细
 * @date 2020/1/15 20:03
 */
public class BxfymxWrapper extends BaseEntityWrapper<Bxfymx, BxfymxVO> {

	/**
	 * 声明全局静态常量
	 */
	private static IBxfymxService bxfymxService;

	private static IDictClient dictClient;

	private static IExpenseAccountService expenseAccountService;

	/**
	 * 静态代码块赋值给静态常量
	 */
	static {
		bxfymxService = SpringUtil.getBean(IBxfymxService.class);
		dictClient = SpringUtil.getBean(IDictClient.class);
		expenseAccountService = SpringUtil.getBean(IExpenseAccountService.class);
	}

	/**
	 * 静态构建对象方法
	 *
	 * @return
	 */
	public static BxfymxWrapper build() {
		return new BxfymxWrapper();
	}


	/**
	 * 视图对象方法
	 *
	 * @param bxfymx
	 * @return
	 */
	@Override
	public BxfymxVO entityVO(Bxfymx bxfymx) {
		BxfymxVO bxfymxVO = BeanUtil.copy(bxfymx, BxfymxVO.class);
		R<String> fplxName = dictClient.getValue("fplx", bxfymx.getFplx());
		if (fplxName.isSuccess()) {
			bxfymxVO.setFylxName(fplxName.getData());
		}
		R<String> fylxName = dictClient.getValue("bx_costtype", bxfymx.getFylx());
		if (fylxName.isSuccess()) {
			bxfymxVO.setFylxName(fylxName.getData());
		}
		R<String> tbfylxName = dictClient.getValue("bx_costtype", bxfymx.getTbfylx());
		if (tbfylxName.isSuccess()) {
			bxfymxVO.setTbfylxName(tbfylxName.getData());
		}
		bxfymxVO.setXmbhName(expenseAccountService.getProjectName(bxfymx.getXmbh()));
		bxfymxVO.setXmbhAbbName(expenseAccountService.getProjectAbbName(bxfymx.getXmbh()));
		return bxfymxVO;
	}

}
